package com.example.kill.service.impl;

import com.example.kill.dao.GoodsMapper;
import com.example.kill.dao.GoodsVoMapper;
import com.example.kill.dao.KillGoodsMapper;
import com.example.kill.pojo.Goods;
import com.example.kill.pojo.KillGoods;
import com.example.kill.service.GoodsService;
import com.example.kill.vo.GoodsVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Resource
    private GoodsVoMapper goodsVoMapper;

    @Resource
    private GoodsMapper goodsMapper;

    @Resource
    private KillGoodsMapper killGoodsMapper;


    @Override
    public List<GoodsVo> getGoodsVoList() {
        return goodsVoMapper.getGoodsVoList();
    }

    @Override
    public GoodsVo getGoodsVoById(long id) {
        return goodsVoMapper.getGoodsVoById(id);
    }

    @Override
    public boolean reduceStock(GoodsVo goodsVo) {
        boolean flag = false;

        try {
            //商品表 减库存
            goodsMapper.reduceStock(goodsVo.getId());
            //秒杀商品表 减库存
            killGoodsMapper.reduceStock(goodsVo.getId());
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }


}
